﻿// =================================================================== 
// 项目说明
//====================================================================
// sushee。@Copy Right 2019
// 文件： JobRecord.cs
// 项目名称：斑马车务
// 创建时间：2019/9/19
// 负责人：sushee
// ===================================================================
using System;
using System.Data;
using System.Collections.Generic;
using Dapper.Extensions;
using YouWei.Infrastructure.Entity;
using YouWei.Infrastructure.Enums;
using YouWei.Infrastructure.Repository;
namespace YouWei.Infrastructure.Service
{
	
	/// <summary>
	///作业记录
	/// </summary>
	public class JobRecordService
	{
         protected JobRecordRepository repository;
         
         public  JobRecordService(){
           repository = new JobRecordRepository("CarServerConnectionString");         
         }
         
        #region 增删改查

        /// <summary>
        /// 插入
        /// </summary>
        /// <param name="entity">实体</param>
        /// <returns></returns>
        public object Insert(JobRecord entity) { return repository.Insert(entity); }

        /// <summary>
        /// 插入
        /// </summary>
        /// <param name="entity">实体</param>
        /// <returns></returns>
        public object Insert(List<JobRecord> entitys) { return repository.Insert(entitys); }

        /// <summary>
        /// 更新
        /// </summary>
        /// <param name="entity">实体</param>
        /// <returns></returns>
        public bool Update(JobRecord entity) { return repository.Update(entity); }

        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="entity">实体</param>
        /// <returns></returns>
        public bool Delete(JobRecord entity) { return repository.Delete(entity); }

        /// <summary>
        /// 删除所有
        /// </summary>
        /// <returns></returns>
        public bool DeleteAll() { return repository.DeleteAll(); }

        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="primaryKey">主键</param>
        /// <returns></returns>
        public bool Delete(int primaryKey) { return repository.Delete(primaryKey); }

        /// <summary>
        /// 查询单个实体
        /// </summary>
        /// <param name="primaryKey">主键</param>
        /// <returns></returns>
        public JobRecord SingleOrDefault(object primaryKey) { return repository.SingleOrDefault(primaryKey); }

       
        /// <summary>
        /// 查询单个实体,如果存在多条则引发异常
        /// </summary>
        /// <param name="primaryKey">主键</param>
        /// <returns></returns>
        public JobRecord Single(object primaryKey) { return repository.Single(primaryKey); }

        /// <summary>
        /// 查询所有
        /// </summary>
        /// <returns></returns>
        public List<JobRecord> QueryAll()
        {
            return repository.QueryAll();
        }

        #endregion

        #region biz logic

	    public JobRecord GetLastExcuteJobRecordInfo(JobEnum jobEnum)
	    {
	        return repository.GetLastExcuteJobRecordInfo(jobEnum);

	    }

	    public int GetErrorCount(int platform, DateTime dt)
	    {
	        return repository.GetErrorCount(platform, dt);
	    }

        /// <summary>
        /// 更新时间\成功数量
        /// </summary>
        /// <param name="categoryID"></param>
        /// <param name="jobID"></param>
        /// <param name="successCount"></param>
        public void UpdateLastDataRecordTime(int categoryID, int jobID, int successCount)
        {
            repository.UpdateLastDataRecordTime(categoryID, jobID, successCount);
        }
        #endregion
    }
	
}